package Class1008;

import NIO.Buffer;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class class01 {

    public static void main(String[] args)  {

//        FileInputStream in = null;
//        try {
//            in = new FileInputStream("src/Class1008/class01");
//            int b = 0;
//            while((b=in.read())!=-1){
//                System.out.println(b);
//            }
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }finally{
//            if(in==null){
//                try {
//                    in.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        }

//        FileOutputStream out = null;
//        try{
//            out = new FileOutputStream("src/Class1008/test.txt",true);
//            String str = "你好";
//            out.write(str.getBytes());
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        } finally {
//            if (out==null){
//                try {
//                    out.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        }

        FileOutputStream out = null;
        FileInputStream in = null;
        long begin = System.currentTimeMillis();
        try {
            in = new FileInputStream("src/Class1008/m.jpg");
            out = new FileOutputStream("src/Class1008/mCopy.jpg");

            int a = 0;
            byte[] buffer = new byte[2048];

            while((a = in.read(buffer))!=-1){
                out.write(buffer,0,a);
            }
            out.flush();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (in==null){
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (out==null){
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        long end = System.currentTimeMillis();

        System.out.println("用时："+(end-begin)+"毫秒~~~");


    }
}
